package com.example.cadmin;

import cn.hutool.cron.CronUtil;
import com.example.cadmin.utils.Netty.NettyServer;
import com.example.cadmin.utils.RFIDMAP;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
@MapperScan("com.example.cadmin.mapper")
public class Application implements CommandLineRunner{
    // 静态方法注入bean解决方案 在springboot的启动类中，定义static变量ApplicationContext，利用容器的getBean方法获得依赖对象
    public static ConfigurableApplicationContext ac;

    public static void main(String[] args) {
        ac = SpringApplication.run(Application.class, args);
        // 支持秒级别定时任务
        CronUtil.setMatchSecond(true);
//         通过配置文件启动定时任务
        CronUtil.start();
    }

    @Override
    public void run(String... args) {
        new Thread(() ->{
            try {
                new NettyServer(9005).run();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }).start();
    }
    public static RFIDMAP rfidmap;

}
